//
//  HNSH_RefundApplyListFooter.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/8.
//

#import "HNSH_RefundApplyListFooter.h"

@interface HNSH_RefundApplyListFooter ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;

/**  */
@property (nonatomic, strong)UIButton * firBtn;
/**  */
@property (nonatomic, strong)UIButton * secBtn;
/** 删除订单 */
@property (nonatomic, strong)UIButton * thrBtn;

/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_RefundApplyListFooter

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_OrderListModel *)model {
    _model = model;
    NSArray * sortArray = [[model.buttons reverseObjectEnumerator] allObjects];
    if (sortArray.count > 0) {
        self.firBtn.hidden = NO;
        self.secBtn.hidden = YES;
        self.thrBtn.hidden = YES;
        HNSH_OrderButtonModel * btnModel = sortArray[0];
        [self.firBtn setTitle:btnModel.name forState:UIControlStateNormal];
        if ([btnModel.style isEqualToString:@"highlight"]) {
            self.firBtn.backgroundColor = [UIColor appGreenColor];
            [self.firBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        } else {
            self.firBtn.backgroundColor = [UIColor appBGColor];
            [self.firBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        }
    }
    if (sortArray.count > 1) {
        self.firBtn.hidden = NO;
        self.secBtn.hidden = NO;
        self.thrBtn.hidden = YES;
        HNSH_OrderButtonModel * btnModel = sortArray[1];
        [self.secBtn setTitle:btnModel.name forState:UIControlStateNormal];
        if ([btnModel.style isEqualToString:@"highlight"]) {
            self.secBtn.backgroundColor = [UIColor appGreenColor];
            [self.secBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        } else {
            self.secBtn.backgroundColor = [UIColor appBGColor];
            [self.secBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        }
    }
    if (sortArray.count > 2) {
        self.firBtn.hidden = NO;
        self.secBtn.hidden = NO;
        self.thrBtn.hidden = NO;
        HNSH_OrderButtonModel * btnModel = sortArray[2];
        [self.thrBtn setTitle:btnModel.name forState:UIControlStateNormal];
        if ([btnModel.style isEqualToString:@"highlight"]) {
            self.thrBtn.backgroundColor = [UIColor appGreenColor];
            [self.thrBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        } else {
            self.thrBtn.backgroundColor = [UIColor appBGColor];
            [self.thrBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        }
    }
}

- (void)configUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.firBtn];
    [self.bgView addSubview:self.secBtn];
    [self.bgView addSubview:self.thrBtn];
    [self.bgView addSubview:self.lineView];
    
    [self.firBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-8);
        make.bottom.mas_equalTo(-12);
        make.width.mas_equalTo(77);
        make.height.mas_equalTo(26);
    }];
    [self.secBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.firBtn.mas_left).offset(-6);
        make.top.width.height.mas_equalTo(self.firBtn);
    }];
    [self.thrBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.secBtn.mas_left).offset(-6);
        make.top.width.height.mas_equalTo(self.firBtn);
    }];
}

- (void)btnAction:(UIButton *)sender{
    if (self.buttonBlock) {
        self.buttonBlock(sender,self.model);
    }
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(20, 0, kScreenWidth-40, 68)];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        [self clipCornerWithView:_bgView cornerWidth:10 cornerType:UIRectCornerBottomLeft|UIRectCornerBottomRight];
    }
    return _bgView;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(11, 18, kScreenWidth-62, 1)];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _lineView;
}

- (UIButton *)firBtn{
    if (!_firBtn) {
        _firBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _firBtn.layer.cornerRadius = 13;
        _firBtn.layer.masksToBounds = YES;
        [_firBtn setTitle:@"立即付款" forState:UIControlStateNormal];
        [_firBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _firBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _firBtn.backgroundColor = [UIColor appGreenColor];
        [_firBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _firBtn.hidden = YES;
    }
    return _firBtn;
}

- (UIButton *)secBtn{
    if (!_secBtn) {
        _secBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _secBtn.layer.cornerRadius = 13;
        _secBtn.layer.masksToBounds = YES;
        [_secBtn setTitle:@"取消订单" forState:UIControlStateNormal];
        [_secBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        _secBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _secBtn.backgroundColor = [UIColor appBGColor];
        [_secBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _secBtn.hidden = YES;
    }
    return _secBtn;
}

- (UIButton *)thrBtn{
    if (!_thrBtn) {
        _thrBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _thrBtn.layer.cornerRadius = 13;
        _thrBtn.layer.masksToBounds = YES;
        [_thrBtn setTitle:@"删除订单" forState:UIControlStateNormal];
        [_thrBtn setTitleColor:[UIColor appBlackLabelColor] forState:UIControlStateNormal];
        _thrBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _thrBtn.backgroundColor = [UIColor appBGColor];
        [_thrBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _thrBtn.hidden = YES;
    }
    return _thrBtn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
